package com.grf.hadoop.word_count;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MyMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    private IntWritable v = new IntWritable(1);
    private Text k = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        String line = value.toString(); //读取一行
        String[] words = line.split(" "); //切割，获得单词数组
        for (String w:words) {
            k.set(w);
            context.write(k,v);
        }
    }
}
